<!Doctype html>
<html>

<head>
    <title>oixan的博客</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8">
    <link rel="stylesheet" type="text/css" href="../css/blog.css">
</head>

<body>
    <div class="head">
        <div class="headnav">
            <div class="naveframe">
                <ul class="navlist">
                    <li>
                        <a href="../index.html">
                            主页
                        </a>
                    </li>
                    <li>
                        <a href="../bloglist.html">
                            博客
                        </a>
                    </li>
                    <li>
                        <a href="../about.html">
                            关于
                        </a>
                    </li>
                </ul>
            </div>
        </div>

        <div class="headtext">
            <div class="headtext1">世界很简单，人类很复杂。</div>
            <div class="headtext2">浮生若梦，寻寻觅觅。</div>
        </div>
    </div>

    <div class="contents-all">
        <div class="contents">

            <div class="frame">
                <div class="title">
                    <h3>python检查文件编码</h3>
                </div>
                <div class="dtime">时间：2018-06-15</div>
                <div class="detail">

                    <p>
                        python检查文件编码,并显示文件内容。
                    </p>
                    <p>
                        <br/>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">import chardet</span>
                    </p>
                    <p>
                        <br/>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">path=input(&#39;输入文件路径名：&#39;)</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">with open(path,&#39;rb&#39;) as f:</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">&nbsp; &nbsp; d=f.read()</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">&nbsp; &nbsp; print(chardet.detect(d))</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">&nbsp; &nbsp; isopen=input(&#39;是否显示内容（输入1显示其他不显示）：&#39;)</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">&nbsp; &nbsp; if isopen==&#39;1&#39;:</span>
                    </p>
                    <p>
                        <span style="font-family: arial, helvetica, sans-serif; font-size: 14px;">&nbsp; &nbsp; &nbsp; &nbsp; print(d.decode(chardet.detect(d)[&#39;encoding&#39;]))</span>
                    </p>
                    <p>
                        <br/>
                    </p>
                    <p>如图；</p>
                    <p>
                        <span style="font-size: 14px;"><img src="../img/blogimg/201806151.jpg" style="width: 60%" title="" alt="201806151.jpg"/></span>
                    </p>

                </div>
<a href="javascript:void(0)" onclick="showPg()">返回</a>
            </div>


        </div>
    </div>
    <div class="footer">
        <div class="footertext">©2018,oixan博客</div>
    </div>
    <span id="backtop" onclick="topFunction()">返回顶部</span>
</body>
<script  src="../js/fanhuiye.js"></script>
</html>